package com.example.sppmode.DataProtocol;

import com.example.sppmode.Common.Constants;

public class CommandInfo {
    public static final int DEVICE_LEFT = 0x01;
    public static final int DEVICE_RIGHT = 0x02;
    public static final int DEVICE_LR = (DEVICE_LEFT | DEVICE_RIGHT);
    public static final int DEVICE_MCU = 0x04;
    public static final int DEVICE_APP = 0x08;
    public static final int DEVICE_PC = 0x10;

    /**
     * Error Code
     */
    public static final int ERROR_CODE_NONE = 0x00;
    public static final int ERROR_CODE_INVALID_FRAME_LEN = 0x01;
    public static final int ERROR_CODE_INVALID_HEAD_FLAG = 0x02;
    public static final int ERROR_CODE_INVALID_FROM = 0x03;
    public static final int ERROR_CODE_INVALID_TO = 0x04;
    public static final int ERROR_CODE_INVALID_CMDID = 0x05;
    public static final int ERROR_CODE_INVALID_DATA_LEN = 0x06;
    public static final int ERROR_CODE_INVALID_CRC = 0x07;
    public static final int ERROR_CODE_INVALID_WAIT_MORE = 0x08;
    public static final int ERROR_CODE_NULL_POINTER = 0x09;
    public static final int ERROR_CODE_SYS_BUSY = 0x10;
    public static final int ERROR_CODE_CALLING = 0x11;
    public static final int ERROR_CODE_NOT_WEARED = 0x12;
    public static final int ERROR_CODE_BAT_LOW = 0x13;
    public static final int ERROR_CODE_PARAM_LEN_INVALID = 0x14;
    public static final int ERROR_CODE_PARAM_OUT_RANG = 0x15;
    public static final int ERROR_CODE_PARAM_SAVE_FAIL = 0x16;


    /* System command */
    public static final int CMDID_DATA_ANALYZE_ERROR = 0x00;
    public static final int CMDID_QUERY_DEV_FW_VER = 0x01;

    public static final int CMDID_BAT_INFO_SYNC = 0x02;

    public static final int CMDID_RECOGNIZED_TAG_REPORT = 0x26;
    public static final int CMDID_KEY_VALUE_ISSUE = 0x27;
    public static final int CMDID_IMAGE_REPORT_IMAGE_INFO = 0x28;
    public static final int CMDID_IMAGE_REPORT_IMAGE_DATA = 0x29;
    /* CMDID End */

    public static final int[] commands = {
            CMDID_DATA_ANALYZE_ERROR,
            CMDID_QUERY_DEV_FW_VER,
            CMDID_BAT_INFO_SYNC,
            CMDID_RECOGNIZED_TAG_REPORT,
            CMDID_KEY_VALUE_ISSUE,
            CMDID_IMAGE_REPORT_IMAGE_INFO,
            CMDID_IMAGE_REPORT_IMAGE_DATA

    };

    /* CMDID Info */
    private int from;
    private int to;
    private int commandID;
    private byte[] cmdData;
    private byte[] frameData;

    /* Command prameter Start */

    //错误码
    private int errCode;

    //设备信息
    private CommandDevInfo commandDevInfo;

    //设备状态信息
    private CommandDevStaInfo commandDevStaInfo;

    //识别标签
    private int recognizedTag;

    private int batteryPercent;

    private CommandImageInfo commandImageInfo;
    /* Command prameter End */


    public CommandInfo() {

    }

    public CommandInfo(int from, int to, int commandID, byte[] cmdData) {
        this.from = from;
        this.to = to;
        this.commandID = commandID;
        this.cmdData = cmdData;
    }

    public int getFrom() {
        return from;
    }

    public void setFrom(int from) {
        this.from = from;
    }

    public int getTo() {
        return to;
    }

    public void setTo(int to) {
        this.to = to;
    }

    public void setToByEarSide(int earSide) {
        if (earSide == Constants.EARSIDE_LEFT)
            this.to = CommandInfo.DEVICE_LEFT;
        else if (earSide == Constants.EARSIDE_RIGHT)
            this.to = CommandInfo.DEVICE_RIGHT;
        else
            this.to = CommandInfo.DEVICE_LR;
    }

    public int getCommandID() {
        return commandID;
    }

    public void setCommandID(int commandID) {
        this.commandID = commandID;
    }

    public int getCmdDataLen() {
        if (cmdData == null)
            return 0;
        else
            return cmdData.length;
    }

    public byte[] getCmdData() {
        return cmdData;
    }

    public void setCmdData(byte[] cmdData) {
        this.cmdData = cmdData;
    }

    public byte[] getFrameData() {
        return frameData;
    }

    public void setFrameData(byte[] frameData) {
        this.frameData = frameData;
    }

    public int getEarSide() {
        return (from == CommandInfo.DEVICE_LEFT) ? Constants.EARSIDE_LEFT : Constants.EARSIDE_RIGHT;
    }

    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public CommandDevInfo getCommandDevInfo() {
        return commandDevInfo;
    }

    public void setCommandDevInfo(CommandDevInfo commandDevInfo) {
        this.commandDevInfo = commandDevInfo;
    }

    public CommandDevStaInfo getCommandDevStaInfo() {
        return commandDevStaInfo;
    }

    public void setCommandDevStaInfo(CommandDevStaInfo commandDevStaInfo) {
        this.commandDevStaInfo = commandDevStaInfo;
    }

    public int getRecognizedTag() {
        return recognizedTag;
    }

    public void setRecognizedTag(int recognizedTag) {
        this.recognizedTag = recognizedTag;
    }

    public int getBatteryPercent() {
        return batteryPercent;
    }

    public void setBatteryPercent(int batteryPercent) {
        this.batteryPercent = batteryPercent;
    }

    public CommandImageInfo getCommandImageInfo() {
        return commandImageInfo;
    }

    public void setCommandImageInfo(CommandImageInfo commandImageInfo) {
        this.commandImageInfo = commandImageInfo;
    }
}
